export default {
  addToCart (state, { detail }) {
    // 添加购物车
    // console.log({ state,detail })
    const isExist = state.cart.some(shop => shop.id === detail.id)
    if (isExist) {
      state.cart = state.cart.map(shop => {
        if (shop.id === detail.id) shop.count++
        return shop
      })
    } else {
      state.cart.push({ ...detail, count: 1, check: true })
    }
  },
  toggleChange (state, { id }) {
    state.cart = state.cart.map(shop => {
      if (shop.id === id) shop.check = !shop.check
      return shop
    })
  },
  changeNum (state, { num, id }) {
    state.cart = state.cart.map(shop => {
      if (shop.id === id) {
        shop.count = num
      }
      return shop
    })
  },
  delshop (state, { id }) {
    state.cart = state.cart.filter(shop => shop.id !== id)
  }
}
